﻿@using TCC.CMFlow.Controllers
@model TCC.CMFlow.Models.Workflow

@{
    ViewBag.Title = "Aprovação de Workflow";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!-- modal placeholder-->
<div id='myModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='myModalContent'></div>
        </div>
    </div>
</div>

<div class="panel panel-info" style="margin-top: 15px">
    <div class="panel-heading clearfix">

        <h3 class="panel-title pull-left"><strong>Workflow</strong></h3>
        <div class="pull-right">
            <a class="btn btn-primary btn-sm" href="@Url.Action("Report", new { workflowID = Model.ID, id = "PDF" })" id="btnImprimir"><span class="glyphicon glyphicon-print"></span> Imprimir</a>
            @if(ViewBag.PermiteReprocessamento)
            {
                <a data-modal="" class="btn btn-primary btn-sm" href="@Url.Action("ReprocessarWorkflow", new { workflowID = Model.ID })" id="btnReprocessa"><span class="glyphicon glyphicon-refresh"></span> Reprocessar</a>
            }
            @Html.ActionLink("Listar Workflows", "Index", null, new { @class = "btn btn-default btn-sm" })
        </div>

    </div>
    <div class="panel-body">

        @if (!ViewBag.PermiteReprocessamento)
        {
            <div class="alert alert-warning">
                <center><span class="glyphicon glyphicon-exclamation-sign"></span> Este workflow está aguardando um Reprocessamento!</center>
            </div>
        }

        <div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-3"><strong>@Html.DisplayNameFor(model => model.CategoriaWorkflow.Nome)</strong></div>
                    <div class="col-md-9">@Html.DisplayFor(model => model.CategoriaWorkflow.Nome)</div>
                </div>
                <div class="row">
                    <div class="col-md-3"><strong>@Html.DisplayNameFor(model => model.DescricaoStatus)</strong></div>
                    <div class="col-md-9">@Html.DisplayFor(model => model.DescricaoStatus)</div>
                </div>
                <div class="row">
                    <div class="col-md-3"><strong>@Html.DisplayNameFor(model => model.DataEmissao)</strong></div>
                    <div class="col-md-9">@Html.DisplayFor(model => model.DataEmissao)</div>
                </div>
            </div>
        </div>

        @Html.Partial("_WorkflowDados", Model.Dados.Where(a => a.Parent == null))

        <div class="panel panel-primary" style="margin-top: 15px">
            <div class="panel-heading clearfix">
                <h3 class="panel-title pull-left"><strong>Arquivos Anexos</strong></h3>
                <div class="btn-group pull-right">
                    <a data-modal="" class="btn btn-primary btn-xs" href="@Url.Action("AnexarArquivo", new { id = Model.ID })" id="btnAdicionar"><span class="glyphicon glyphicon-paperclip"></span> Anexar Arquivo</a>
                </div>
            </div>

            <div class="panel-body">

                <div class="alert alert-info">
                    <center>Nenhum arquivo anexado!</center>
                </div>

            </div>
        </div>

        @Html.Partial("_WorkflowAprovacoes", Model.Aprovacoes)

        <div class="panel panel-primary" style="margin-top: 15px">
            <div class="panel-heading clearfix">
                <h3 class="panel-title pull-left"><strong>Fluxo de Aprovação</strong></h3>
            </div>
            <div class="panel-body">
                @{
                    int count = 0;
                }

                @if (!Model.CategoriaWorkflow.CategoriaGrupos.Any())
                {
                    <div class="alert alert-danger">
                        <center>
                            <span class="glyphicon glyphicon-info-sign"></span> Nenhum grupo de aprovação configurado na categoria!
                        </center>
                    </div>
                }
                else
                {
                    foreach (var item in Model.CategoriaWorkflow.CategoriaGrupos)
                    {
                        if (count % 3 == 0)
                        {
                            @:<div class="row">
                        }

                        <div class="col-lg-4 col-md-4 col-sm-4">
                            <div class="panel panel-default">
                                <div class="panel-heading clearfix">
                                    <h3 class="panel-title pull-left">
                                        <span class="badge" title="sequencia de aprovação">@Html.DisplayFor(modelItem => item.sequenciaAprovacao)</span>
                                        <strong>@Html.DisplayFor(modelItem => item.GrupoAprovacao.Nome)</strong>
                                    </h3>
                                </div>
                                <div class="panel-body">
                                    <div class="info">
                                        @Html.DisplayFor(modelItem => item.GrupoAprovacao.Descricao)
                                    </div>
                                </div>
                                <table class="table">
                                    <tr class="active">
                                        <th>
                                            <span class="glyphicon glyphicon-user"></span> Aprovadores
                                        </th>
                                    </tr>
                                    @if(!item.Usuarios.Any())
                                    {
                                        <tr>
                                            <td>
                                                <div class="alert alert-danger">
                                                    <center>
                                                        <span class="glyphicon glyphicon-info-sign"></span> Nenhum usuário associado!
                                                    </center>
                                                </div>
                                            </td>
                                        </tr>
                                    }
                                    else
                                    {
                                        foreach (var usuario in item.Usuarios)
                                        {
                                            <tr>
                                                <td>
                                                    @Html.DisplayFor(modelItem => usuario.UserName)
                                                    <div class="pull-right">
                                                        @Html.Action("UsuarioAprovacao", new { workflow = Model, usuarioId = usuario.Id })
                                                    </div>
                                                </td>
                                            </tr>
                                        }
                                    }
                                </table>
                                @*<div class="panel-footer">
                                    <span class="text-info glyphicon glyphicon-dashboard"></span> Pendente
                                </div>*@
                            </div>
                        </div>
                    
                        count++;

                        if (count % 3 == 0 || (Model.CategoriaWorkflow.CategoriaGrupos.Count == count))
                        {
                            @:</div>
                        }
                    }
                }
            </div>
        </div>
    </div>

    @if (ViewBag.ExibeControles)
    {
        <div class="panel-footer clearfix">
            <div class="pull-right">
                <a data-modal="" class="btn btn-success" href="@Url.Action("AprovarWorkflow", new { workflowID = Model.ID })" id="btnAprovar"><span class="glyphicon glyphicon-thumbs-up"></span> Aprovar</a>
                <a data-modal="" class="btn btn-danger" href="@Url.Action("ReprovarWorkflow", new { workflowID = Model.ID })" id="btnReprovar"><span class="glyphicon glyphicon-thumbs-down"></span> Reprovar</a>
                <a data-modal="" class="btn btn-warning" href="@Url.Action("CancelarWorkflow", new { workflowID = Model.ID })" id="btnCancelar"><span class="glyphicon glyphicon-remove"></span> Cancelar</a>
            </div>   
        </div>
    }
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/modalform")
}